#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
int num[30], a[30];

void solve() {
	int n; cin >> n;
	string s; cin >> s;
	memset(num, 0, sizeof num);
	memset(a, 0, sizeof a);
	if (n & 1) {
		cout << -1 << endl;
		return;
	}

	for (int i = 0; i < n; i++) {
		num[s[i] - 'a']++;
	}
	int mx = 0;
	for (int i = 0; i < 26; i++) {
		mx = max(mx, num[i]);
	}
	if (mx > n / 2) {
		cout << -1 << endl;
		return;
	}

	int cnt = 0;
	for (int i = 0; i < n / 2; i++) {
		if (s[i] == s[n - i - 1]) {
			a[s[i] - 'a']++;
			cnt++;
		}
	}
	mx = 0;
	for (int i = 0; i < 26; i++) {
		mx = max(mx, a[i]);
	}
	if (mx <= cnt - mx) {
		cout << (cnt + 1) / 2 << endl;
	}
	else {
		cout << mx << endl;
	}
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t; cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}